﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NetDon.OA.Portal.HtmlTool
{
    public static class HtmlUtility
    {
        public static string ReplaceText1(this string source, string tag, string value )
        {
            return source.Replace(tag, value);
        }

        public static string ReplaceText2(this string source, string tag, string value)
        {
            return source.Replace(tag, HttpContext.Current.Server.HtmlEncode(value));
        }

        public static string ReplaceHtml(this string source, string tag, string value)
        {
            return source.Replace(tag, value);
        }

        public static string ReplaceImg(this string source, string tag, string value)
        {
            var baseUrl = System.Configuration.ConfigurationSettings.AppSettings["picBaseUrl"];

            var alt = tag.Replace("<O:IMAGE>", "").Replace("</O:IMAGE>", "");
            var img = string.Empty;
            if (!string.IsNullOrWhiteSpace(value))
            {
                img = string.Format("<IMG alt='{0}' src='{1}' border=0>", alt, baseUrl + value);
            }
    
            return source.Replace(tag, img);
        }

        public static string GetFullImgUrl(this string source)
        {
            return System.Configuration.ConfigurationSettings.AppSettings["picBaseUrl"] + source;
        }
    }
}